@echo off
setlocal

:: 设置颜色输出
set RED=[91m
set GREEN=[92m
set NC=[0m

:: 创建并进入构建目录
if not exist build mkdir build
cd build

:: 检查CMake是否安装
where cmake >nul 2>nul
if %ERRORLEVEL% neq 0 (
    echo %RED%Error: CMake is not installed%NC%
    exit /b 1
)

:: 检查Qt是否安装
where qmake >nul 2>nul
if %ERRORLEVEL% neq 0 (
    echo %RED%Error: Qt is not installed%NC%
    exit /b 1
)

:: 构建类型
set BUILD_TYPE=Release
if not "%1"=="" set BUILD_TYPE=%1
echo %GREEN%Building with type: %BUILD_TYPE%%NC%

:: 运行CMake配置
cmake -DCMAKE_BUILD_TYPE=%BUILD_TYPE% ..
if %ERRORLEVEL% neq 0 (
    echo %RED%CMake configuration failed%NC%
    exit /b 1
)

:: 编译
cmake --build . --config %BUILD_TYPE%
if %ERRORLEVEL% neq 0 (
    echo %RED%Build failed%NC%
    exit /b 1
)

:: 运行测试
echo %GREEN%Running tests...%NC%
ctest --output-on-failure
if %ERRORLEVEL% neq 0 (
    echo %RED%Tests failed%NC%
    exit /b 1
)

echo %GREEN%Build completed successfully%NC%
endlocal 